package com.py.credit.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.ContentStyle;
import com.py.credit.entity.ContentStyleInfo;
import com.py.credit.entity.TableResult;
import com.py.credit.service.ContentStyleService;

@RestController
@RequestMapping("/contentStyle")
public class ContentStyleController {

	@Autowired
	private ContentStyleService contentStyleService;

	@RequestMapping("/update.json")
	public RestServiceResult<Object> update(
			@RequestParam(value = "contentId", defaultValue = "", required = true) String contentId,
			@RequestParam(value = "contentStyle", defaultValue = "", required = true) String contentStyle) {

		if (StringUtils.isNotBlank(contentStyle)) {

			List<ContentStyle> contentStyles = JSONArray.parseArray(contentStyle, ContentStyle.class);

			contentStyleService.update(contentId, contentStyles);

		}

		return new RestServiceResult<Object>();

	}

	@RequestMapping("/getDetail.json")
	public RestServiceResult<List<TableResult>> getDetail(
			@RequestParam(value = "contentId", defaultValue = "", required = true) String contentId,
			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "kId", defaultValue = "", required = true) String kId) {
		/*
		 * type 'YZS' || 'XYHC'
		 */
		List<TableResult> detail = contentStyleService.getDetail(contentId, type, kId);

		return new RestServiceResult<List<TableResult>>(detail);

	}

	@RequestMapping("/getTableList.json")
	public RestServiceResult<List<ContentStyleInfo>> getTableList() {

		List<ContentStyleInfo> list = contentStyleService.getTableList();

		return new RestServiceResult<List<ContentStyleInfo>>(list);

	}

}
